angular.module('ionicApp', ['ionic, commentService'])

.controller('AppCtrl', function($scope, $http,$ionicModal, Contact) {
$scope.sideMenuClick = function() {
    console.log('sideMenuClick');
    $scope.toggleMenu();
  };
Contact.get()
	.success(function(data) {
		 $scope.contacts = data;
	});


$scope.showContact = function(id) {
	Contact.show(id).success(function(data){
		$scope.contactsimple = angular.copy(data);
	});
};


  $scope.contactsRightButtons = [
    {
      type: 'button-icon ion-plus-round',
      tap: function(e) {
        $scope.modal.show();
      }
    }
  ];


  $ionicModal.fromTemplateUrl('addContact.html', function(modal) {
    $scope.modal = modal;
  }, {
    animation: 'slide-in-up',
    focusFirstInput: true
  });
})


.controller('addContactCtrl', function($scope, $http,$ionicModal, Contact) {
  $scope.newUser = {};
  $scope.createContact = function() {
			// save the comment. pass in comment data from the form
			// use the function we created in our service
			Contact.save( $scope.newUser)
				.success(function(data) {
					// if successful, we'll need to refresh the comment list
					Contact.get()
						.success(function(getData) {
							console.log(getData);
							$scope.contacts = getData;
							console.log($scope.contacts);
							$scope.modal.hide();
							
						});
				})
				.error(function(data) {
					console.log(data);
				});
		};
	
})

.controller('showContactCtrl', function($scope, $http,$ionicModal, Contact) {
  $scope.showClick = function(id) {
		console.log(id);
		$scope.modal.show();
	};
});